#include <gflags/gflags.h>

#include <memory>
#include <thread>

#include "../../common/etcd.h"
#include "../../common/log.h"

DEFINE_int32(level, 1, "日志等级");
DEFINE_bool(mode, false, "调试模式-false, 发布模式-true");
DEFINE_string(path, "./logfile", "发布模式下日志输出到的文件路径");

DEFINE_string(etcd_host, "http://127.0.0.1:2379", "etcd服务器地址");
DEFINE_string(base_service, "/service", "服务监控根目录");
DEFINE_string(instance_name, "/user/instance", "当前实例名称");
DEFINE_string(access_host, "127.0.0.1:8080", "当前实例的外部访问地址");

int main(int argc, char* argv[]) {
    gflags::ParseCommandLineFlags(&argc, &argv, true);
    initLogger(FLAGS_level, FLAGS_mode, FLAGS_path);

    auto registry = std::make_shared<Registry>(FLAGS_etcd_host);

    registry->registry(FLAGS_base_service + FLAGS_instance_name,
                       FLAGS_access_host);

    std::this_thread::sleep_for(std::chrono::seconds(10));

    return 0;
}

// #include <etcd/Client.hpp>
// #include <etcd/KeepAlive.hpp>
// #include <etcd/Response.hpp>
// #include <string>
// #include <thread>

// #include "../spdlog/log.h"

// int main() {
//     initLogger(1, false, "log.file");

//     const std::string etcd_host = "http://127.0.0.1:2379";

//     // 1. 实例化客户端对象
//     etcd::Client client(etcd_host);

//     // 2. 获取租约保活对象，并创建一个指定有效时长的租约
//     auto keep_alive = client.leasekeepalive(3).get();

//     // 3. 获取租约id
//     auto lease_id = keep_alive->Lease();

//     // 4. 新增数据
//     auto resp1 = client.put("/source/user", "127.0.0.1:8080",
//     lease_id).get(); if (resp1.is_ok() == false) {
//         LOG_ERROR("新增数据失败 {}", resp1.error_message());
//         return -1;
//     }
//     auto resp2 = client.put("/source/friend", "127.0.0.1:9090",
//     lease_id).get(); if (resp2.is_ok() == false) {
//         LOG_ERROR("新增数据失败 {}", resp2.error_message());
//         return -1;
//     }

//     std::this_thread::sleep_for(std::chrono::seconds(10));

//     return 0;
// }